//
//  BigDataProportionView.m
//  魔兽大数据
//
//  Created by 王右 on 2017/11/14.
//  Copyright © 2017年 王右. All rights reserved.
//

#import "BigDataProportionView.h"
#import <Masonry/Masonry.h>
#import "UIColor+Hex.h"

@interface BigDataProportionView()
//联盟图标
@property (weak, nonatomic) IBOutlet UIImageView *allianceIconImageView;
//部落图标
@property (weak, nonatomic) IBOutlet UIImageView *horderIconImageView;
//联盟人数
@property (weak, nonatomic) IBOutlet UILabel *allianceCountLabel;
//部落人数
@property (weak, nonatomic) IBOutlet UILabel *horderCountLabel;
//分割线
@property (weak, nonatomic) IBOutlet UILabel *separationLine;
//联盟占比
@property (weak, nonatomic) IBOutlet UILabel *allianceProportionLabel;
//部落占比
@property (weak, nonatomic) IBOutlet UILabel *horderProportionLabel;
//占比的容器视图
@property (weak, nonatomic) IBOutlet UIView *containerView;
//联盟数
@property (nonatomic, assign) CGFloat allianceNumbers;
//部落数
@property (nonatomic, assign) CGFloat horderNumbers;
//比例尺
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *proportion;

@end


@implementation BigDataProportionView

- (void)awakeFromNib{
    [super awakeFromNib];
    self.layer.borderWidth = .8;
    self.layer.borderColor = [UIColor colorWithHexString:@"#f9f9f9"].CGColor;
}

- (void)setDataWithAllianceNumbers:(CGFloat)allianceNumbers horderNumbers:(CGFloat)horderNumers{
    self.allianceNumbers = allianceNumbers;
    self.horderNumbers = horderNumers;
    float propor = allianceNumbers / (horderNumers + allianceNumbers);
    
    //界面适配防止过小 或 过大
    if (propor < 0.12) {
        propor = 0.12;
    }else if (propor > 0.88){
        propor = 0.88;
    }else{
        propor = propor;
    }
    CGFloat screenWidth = [UIScreen mainScreen].bounds.size.width;
    
    
    self.proportion.constant = (screenWidth - 80) * propor;
    
    self.allianceCountLabel.text = [NSString stringWithFormat:@"%@",@(allianceNumbers)];
    self.horderCountLabel.text = [NSString stringWithFormat:@"%@",@(horderNumers)];
    
    float alliancePercent = _allianceNumbers / (_allianceNumbers + _horderNumbers) * 100;
    float horderPercent = _horderNumbers / (_allianceNumbers + _horderNumbers) * 100;
    
    self.allianceProportionLabel.text  = [NSString stringWithFormat:@"%.1f%%",alliancePercent];
    self.horderProportionLabel.text = [NSString stringWithFormat:@"%.1f%%",horderPercent];
    
}

@end
